<template>
  <div class="comment-reply">
    <van-nav-bar :title="`${comment.reply_count}条回复`">
      <van-icon slot="left" name="cross" @click="$emit('cross-btn')" />
    </van-nav-bar>

    <div class="scroll-wrap">
      <!-- 评论内容 -->
      <CommentItem :comment="comment" />

      <!-- 评论列表 -->
      <van-cell title="全部评论" />
      <CommentList :list="commentList" :source="comment.com_id" type="c" />

      <!-- 发布评论 -->
      <div class="post-wrap">
        <van-button
          @click="isPostRplShow = true"
          class="post-btn"
          size="small"
          round
          >写评论</van-button
        >
      </div>

      <van-popup v-model="isPostRplShow" position="bottom">
        <CommentPost @post-success="onPostSuccess" :target="comment.com_id" />
      </van-popup>
    </div>
  </div>
</template>

<script>
import CommentItem from './comment-item.vue'
import CommentList from './comment-list.vue'
import CommentPost from './comment-post.vue'

export default {
  name: 'CommentReply',
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  components: { CommentItem, CommentList, CommentPost },
  data () {
    return {
      isPostRplShow: false,
      commentList: []
    }
  },
  methods: {
    onPostSuccess (data) {
      this.comment.reply_count++
      this.isPostRplShow = false
      this.commentList.unshift(data.new_obj)
    }
  }
}
</script>

<style scoped lang="less">
.scroll-wrap {
  position: fixed;
  top: 46px;
  left: 0;
  right: 0;
  bottom: 44px;
  overflow-y: auto;
}

.post-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .post-btn {
    width: 60%;
  }
}
</style>
